package com.aboat.view.panel;

import com.aboat.view.WindowFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 * 其它配置面板
 *
 * @author aboat
 * @email clear_windy@yeah.net
 * @create 2017-04-09 12:58
 */
public class OtherPanel extends JPanel {
    public OtherPanel(){
        setPreferredSize(new Dimension(975,110));
        setLayout(new FlowLayout(FlowLayout.LEFT));
        this.setBorder(BorderFactory.createLineBorder(Color.gray,1));

        JLabel threadLabel = new JLabel("线程数:");
        WindowFrame.threadSlider.setPreferredSize(new Dimension(400, 50));
        WindowFrame.threadSlider.setSnapToTicks(true);//设置滑块必须停在刻度处
        WindowFrame.threadSlider.setPaintTicks(true);//设置绘制刻度
        WindowFrame.threadSlider.setMajorTickSpacing(1);//设置主、次刻度的间距
        WindowFrame.threadSlider.setMinorTickSpacing(1);
        WindowFrame.threadSlider.setPaintLabels(true);
        this.add(threadLabel);
        this.add(WindowFrame.threadSlider);

        JLabel depthLabel = new JLabel("爬取深度:");
        WindowFrame.depthSlider.setPreferredSize(new Dimension(400, 50));
        //设置滑块必须停在刻度处
        WindowFrame.depthSlider.setSnapToTicks(true);
        WindowFrame.depthSlider.setPaintTicks(true);//设置绘制刻度
        //设置主、次刻度的间距
        WindowFrame.depthSlider.setMajorTickSpacing(1);
        WindowFrame.depthSlider.setMinorTickSpacing(1);
        WindowFrame.depthSlider.setPaintLabels(true);
        this.add(depthLabel);
        this.add(WindowFrame.depthSlider);

        JLabel storagePath = new JLabel("存储路径:");
        JButton pathButton = new JButton("设置");
        pathButton.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                fileChooser.setDialogTitle("设置爬取图片存储路径");
                int result = fileChooser.showOpenDialog(new JPanel());
                if(result == JFileChooser.APPROVE_OPTION){
                    File file = fileChooser.getSelectedFile();
                    String filePath  = file.getAbsolutePath();
                    WindowFrame.textStoragePath.setText(filePath);
                }
            }
        });
        this.add(storagePath);
        this.add(pathButton);
        this.add(WindowFrame.textStoragePath);


        JLabel tagLabel = new JLabel("提取标签:");
        this.add(tagLabel);
        this.add(WindowFrame.tagField);
    }
}
